package model

import (
	"ginProject/config/global"
	"ginProject/internal/request"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Mobile   string  `json:"mobile"`
	Password string  `json:"password"`
	Avator   string  `json:"avator"`
	Identity int     `json:"identity"`
	Balance  float64 `json:"balance"`
	Score    int     `json:"score"`
}

func CheckUser(mobile string) User {
	//通过手机号查询  用户是否存在
	var user User
	global.Db.Where("mobile =?", mobile).First(&user)
	return user
}

func GetUserInfoById(id string) User {
	var user User
	global.Db.Where("id =?", id).First(&user)
	return user
}

func Register(request request.RegisterRequest) error {
	user := User{
		Mobile:   request.Mobile,
		Password: request.Password,
	}
	err := global.Db.Create(&user).Error
	if err != nil {
		zap.Error(err)
	}
	return err
}
